﻿
$(function () {
    function eNameCheck() {
        
    }
    var check = "ok";
    $('#doc-vld-msg').validator({
        onValid: function (validity) {
            $(validity.field).closest('.am-form-group').find('.am-alert').hide();
            console.log(validity);
            if (validity.valid) {
                $("input[name='eName']").blur(function () {
                    alert("a");
                    $.ajax({
                        type: 'post',
                        url: '/User/EmailCheck',
                        data: { eName: $("input[name='eName']").val() },
                        cache: false,
                        dataType: 'json',
                        success: function (data) {
                            if (data.Statu) {
                                check = "err";
                            }
                        }
                    });
                    if (check == "err") {
                        validity.valid = false;
                        $("input[name='eName']").attr("data-validation-message", "这个名字被别人使用了");
                        console.log(validity);
                        return validity;

                    }
                    else {
                        $("input[name='eName']").attr("data-validation-message", "至少3个字符,最多10个字符");
                    }
                });
            }
            
        },

        onInValid: function (validity) {
            var $field = $(validity.field);
            var $group = $field.closest('.am-form-group');
            var $alert = $group.find('.am-alert');
            // 使用自定义的提示信息 或 插件内置的提示信息
            var msg = $field.data('validationMessage') || this.getValidationMessage(validity);
            if (!$alert.length) {
                $alert = $('<div class="am-alert am-alert-danger"></div>').hide().
                  appendTo($group);
            }

            $alert.html(msg).show();
        }
    });
});
